<?php

class Application_Model_User extends Application_Model_DbTable_User {

    function checkUnique($username) { // ammar
        $select = $this->_db->select()
                        ->from($this->_name, array('username'))
                        ->where('username=?', $username);
        $result = $this->getAdapter()->fetchOne($select);
        if ($result) {
            return true;
        }
        return false;
    }

        function checkUserValid($username,$id) { // ammar
        $select = $this->_db->select()
                        ->from($this->_name, array('username'))
                        ->where('username=?', $username)
                        ->where('id != ?', $id);
        $result = $this->getAdapter()->fetchOne($select);
        if ($result) {
            return true;
        }
        return false;
    }

    function Verify($token, $email) { // ammar
        $table = new Application_Model_User();
        $data = array('status' => 'enable');
        $where = " email = '" . $email . "' ";
        $where .="and  token ='" . $token . "' ";
        $x = $table->update($data, $where);
        return $x;
    }

    public function getAllUsers() {
        $select = $this->_db->select()
                        ->from($this->_name);
        $result = $this->getAdapter()->fetchAll($select);
        return $result;
    }

    public function getUser($id) {
        $select = $this->_db->select()
                        ->from($this->_name)
                        ->where('id = ?', $id);
        $result = $this->getAdapter()->fetchAll($select);
        return $result;
    }

}

